home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP0492.ARJ / PCNVRT.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  854b  |  37 lines

  1. /*
  2. **  demo code for converting Pascal string to C strings
  3. **
  4. **  public domain by Bob Stout
  5. */
  6.  
  7. #define Pconvert(s) {int n; n = *s++; s[n] = '\0';}
  8.  
  9.         char *string = malloc(82);   /* use instead of string[82] */
  10.  
  11.         fgets(string, 81, inFile);   /* get 80-char pascal string */
  12.         Pconvert(string);            /* convert it in place       */
  13.  
  14. /*
  15. **  Warning: The above macro is incompatible with strings that must
  16. **           be freed. To avoid this, use the following functions.
  17. **
  18. **  public domain by Jan Vroonhof
  19. */
  20.  
  21. #include "string.h"
  22. #include "stdio.h"
  23.  
  24. typedef pastr unsigned char
  25.  
  26. void pascal ptocstr(char *dest,pastr *org)
  27. {
  28.       memcpy(dest,org+1,org[0]);
  29.       dest[org[0]]=0;
  30. }
  31.  
  32. void pascal ctopstr(pastr *dest,char *org)
  33. {
  34.       dest[0]=strlen(org);
  35.       memcpy(dest+1,org,dest[0]);
  36. }
  37.